#ifndef MODBUSCLIENT_DEV_H
#define MODBUSCLIENT_DEV_H

#include <QString>
#include <QMutex>
#include <QQueue>
#include <QWaitCondition>
#include <QVector>
#include <QObject>

#include "modbus.h"
#include "ModbusComm.h"

class ModbusClient;

class ModbusClient_dev : public QObject
{
    Q_OBJECT
public:
    enum FloatType{
        FloatType_ABCD,
        FloatType_BADC,
        FloatType_CDAB,
        FloatType_DCBA
    };
    enum IntType{
        IntType_AB,
        IntType_BA,
    };
    ModbusClient_dev(QObject *parent = nullptr);
    ~ModbusClient_dev();
    void setDeviceId(uint8_t device_id);
    void read_registers(uint16_t address, uint16_t length,uint8_t cmdType = 0, int askTime = 0);
    void read_coils(uint16_t address, uint16_t length,uint8_t cmdType = 0, int askTime = 0);
    void write_registers(uint16_t address, uint16_t length, uint16_t *data,uint8_t cmdType = 0, int askTime = 0);
    void write_coils(uint16_t address, uint16_t length, uint8_t *data,uint8_t cmdType = 0, int askTime = 0);
    void write_coil(uint16_t address, uint8_t data,uint8_t cmdType = 0, int askTime = 0);
    void write_float(uint16_t address, float data,int type = FloatType_ABCD,uint8_t cmdType = 0, int askTime = 0);
    void write_int(uint16_t address, int data,int type = IntType_AB,uint8_t cmdType = 0, int askTime = 0);
    void setModbusClient(ModbusClient * cl);
    virtual void reciveRequest(ModbusRequest request);
    uint8_t getDeviceId(); 
private:
    uint8_t m_device_id;
    ModbusClient *m_client =nullptr;
signals:
    void read_register( ModbusRequest &request);
};

#endif // MODBUSCLIENT_DEV_H
